package com.example.ivos.dict.controller;

import com.example.ivos.base.response.JsonResult;
import com.example.ivos.dict.pojo.dto.DictParam;
import com.example.ivos.dict.pojo.dto.DictQuery;
import com.example.ivos.dict.pojo.vo.DictVO;
import com.example.ivos.dict.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "字典管理")
@RestController
@Slf4j
@RequestMapping("/v1/dict/")
public class DictController {
    @Autowired
    private DictService dictService;

    @ApiOperation(value = "字典列表")
    @GetMapping("select")
    public JsonResult select(DictQuery dictQuery){
        log.debug("查询字典列表dictQuery:{}", dictQuery);
        List<DictVO> dictVOList = dictService.select(dictQuery);
        return JsonResult.ok(dictVOList);
    }

    @ApiOperation(value = "字典管理")
    @PostMapping("save")
    public JsonResult save(DictParam dictParam){
        log.debug("保存字典信息dictParam:{}", dictParam);
        dictService.save(dictParam);
        return JsonResult.ok();
    }

    @ApiOperation(value = "删除字典")
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("删除字典id:{}", id);
        dictService.del(id);
        return JsonResult.ok();
    }
}
